package com.shenmazong.servereduresume.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shenmazong.servereduresume.dto.TbCertificate;
import com.shenmazong.servereduresume.dto.TbEducation;
import com.shenmazong.servereduresume.mapper.TbEducationMapper;
import com.shenmazong.servereduresume.service.TbEducationService;
import com.shenmazong.utils.ResultResponse;
import com.shenmazong.vo.BatchChooseIdVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 */
@Service
public class TbEducationServiceImpl extends ServiceImpl<TbEducationMapper, TbEducation>
implements TbEducationService {
    @Autowired
    private TbEducationMapper tbEducationMapper;
    @Override
    public ResultResponse findByInformation(BatchChooseIdVo batchChooseIdVo) {
        Object o = batchChooseIdVo.getParamMap().get("informationId");
        if (o==null){
            return ResultResponse.FAILED("非法参数");
        }
        List<TbEducation> one = null;
        try {
        one = tbEducationMapper.selectList(new QueryWrapper<TbEducation>().lambda().eq(TbEducation::getInformationId, o)
                .eq(TbEducation::getDeleteFlag, 0));
        } catch (Exception e) {
            e.printStackTrace();
            return ResultResponse.FAILED();
        }
        return ResultResponse.SUCCESS(one);
    }

    @Override
    public ResultResponse saveEducation(TbEducation tbEducation) {
        try {
            tbEducationMapper.insert(tbEducation);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultResponse.FAILED();
        }
        return ResultResponse.SUCCESS();
    }

    @Override
    public ResultResponse updateEducation(TbEducation tbEducation) {
        try {
            tbEducationMapper.updateById(tbEducation);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultResponse.FAILED();
        }
        return ResultResponse.SUCCESS();
    }

    @Override
    public ResultResponse deleteEducation(BatchChooseIdVo batchChooseIdVo) {
        if (batchChooseIdVo.getIds().size()==0){
            return ResultResponse.FAILED("至少选择一个删除");
        }
        try {
            for (Long id : batchChooseIdVo.getIds()) {
                TbEducation certificate = tbEducationMapper.selectById(id);
                certificate.setDeleteFlag((byte) 1);
                tbEducationMapper.updateById(certificate);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return ResultResponse.FAILED();
        }
        return ResultResponse.SUCCESS();
    }
}




